﻿using Common.BaseLibrary;
using Common.BaseLibrary.Utils;
using Solution.WebApp.Commons;
using Solution.WebApp.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Solution.WebApp.Controllers
{
    public class HomeController : BaseController
    {


        [HttpGet]
        public ActionResult Login()
        {
            return View();
        }


        [HttpGet]
        public ActionResult Index()
        {

            string clientIp = ComputerInfoHelper.Instance.GetClientIp();
            //string clientIp = IPAddress.GetIPAddress();
            //string clientIp = "114.248.126.196";
            try
            {
                string location = IpManager.Instance.Find(clientIp)[1];//获取地址
                ViewBag.ClientLocation = location;//把地址放在viewbag中
                //ViewBag.ClientLocation = "北京";
                string cityCode = CityManager.Instance.GetCityCodeByCityName(location);
                //string cityCode = CityManager.Instance.GetCityCodeByCityName("北京");
                ViewBag.CityCode = cityCode;
                WeatherJSON weather = WeatherManager.Instance.GetWeather(cityCode);
                ViewBag.Weather = weather.weatherinfo.weather;
                ViewBag.temp = weather.weatherinfo.temp1;
                ViewBag.Icon = weather.weatherIcon;
                ViewBag.Img = weather.weatherImg;

            }
            catch (Exception)
            {
                //ViewBag.ClientLocation = IpManager.Instance.Find("172.16.11.85")[1];
                ViewBag.ClientLocation = "未知地址";
                WeatherJSON weather = WeatherManager.Instance.GetWeather("101010100");
                ViewBag.Weather = weather.weatherinfo.weather;
                ViewBag.temp = weather.weatherinfo.temp1;
                ViewBag.Icon = weather.weatherIcon;
                ViewBag.Img = weather.weatherImg;
            }

          

            return this.View();
        }







    }
}